home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12804 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news.inet.fi!usenet
  2. From: Risto Jokinen <hatrjo@hat-fi.kone.com>
  3. Newsgroups: comp.arch.embedded,comp.lang.c
  4. Subject: Re: Using malloc of C on embedded system?
  5. Date: 2 Apr 1996 17:16:42 GMT
  6. Organization: Telecom Finland News Service
  7. Message-ID: <4jrndq$ate@kuikka.inet.fi>
  8. References: <4jml7h$cbc@castor.usc.edu>
  9. NNTP-Posting-Host: 138.249.2.139
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14.  
  15. you can use malloc and even free in embedded systems, but if you like to use free, 
  16. you should change malloc/free functions to have clear book-keeping which is needed 
  17. during the software testing/runtime error recovery(watchdog!)
  18.  
  19. some simple instructions if you like to use malloc and free
  20.  
  21. - malloc memory in fixed size blocks (like buffer pool)
  22. - before first malloc, initialice whole free memory to the fixed blocks (partitions)
  23.   and have link fields between them.
  24.   [block1]-->[block2]->[block3] etc... set 'free' pointer to the block1
  25.  
  26. - during the malloc, reserve block1 by assigning free pointer to the next pointer 
  27. which was found from the beginning of block1 and at a same time write some debugging
  28. who-why-when information to the end of block1
  29. - when you run free, join this block to the chain by changing 'free' pointer to 
  30. point this block and this block is then wired to the previous free block. add more
  31. who-why-when information to this block.
  32.  
  33. - run system for a while (minute, day, week), and look over all blocks (using some 
  34. tool) and check if there is lost blocks, or some strange who-what-when syndromes 
  35. etc.
  36.  
  37. This mechanism works. random size malloc/free does not work on embedded systems, or
  38. at least it is impossible to debug, and can be VERY slow. fixed size partition pool
  39. manager takes <<50us for malloc/free in any processor.
  40.  
  41. -- Risto Jokinen
  42.  
  43.  
  44.